clear;

%%%%%%%%%%%%%%%%%%%%%%Data%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data = dataset('File','table4_data.csv','Delimiter',',');

N = 2519;
iter = 1;
warning('off','all');
stations = [data.station_id1, data.station_id2];

X = [data.constant data.num_stations_2 data.poll_date_1 data.poll_date_2 data.poll_date_3 data.poll_date_4 ...
    data.z1 data.z2 data.educ_1 data.educ_2 data.educ_3 data.educ_4 data.educ_5 data.educ_6 data.educ_7 data.educ_8 ...
    data.asset_index data.z13 data.caste_1 data.caste_2 data.caste_3 data.caste_4 ...
    data.religion_1 data.religion_2 data.location_1 data.location_2 data.location_3 ...
    data.interview_1 data.interview_2 data.interview_3 data.interview_4 data.interview_5 data.interview_6 data.interview_7];

vars = {'issue_price',	'issue_dev','issue_corrupt'	,'issue_unemp','party_admin','party_relig','party_security','party_leader','party_gifts','voted_votebuyer'};

for j= 1:length(vars)
        y = data.(vars{j});
        idx = find(~isnan(y));
        [N1, ~] = size(idx);
    
        [beta,se,p,r2,F,control_mean,N,C,T] = fereg(y(idx),data.treat(idx),X(idx,:),stations(idx,:),2);
        p_ri_fe = ri_fe(iter,beta,se,y(idx),X(idx,:),stations(idx,:),2);
        results1(:,j) = [beta(1);se(1);p(1);p_ri_fe(1);r2;T+C];
    
end

format bank;
fprintf('Columns 1\n');
disp(results1(:,:));
